// pages/grade/grade.js
const host=getApp().host;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    pageSize:10,
    total:0,
    admin:{}
  },

  /**点击成绩条目 */
  feedback(e){
    wx.showActionSheet({
      itemList: ['成绩反馈','反馈进度'],
      success:res=> {
        let id=e.currentTarget.dataset.id;
        if(res.tapIndex==0){
          wx.showModal({
            title: '对成绩反馈',
            editable:true,
            placeholderText:'反馈信息',
            success:res1=>{
              if (res1.confirm) {
                wx.request({
                  url: host+'/client/gradeFeedback/add',
                  method:'POST',
                  data:{
                    grade:id,
                    content:res1.content
                  },
                  header:{
                    'content-type': 'application/x-www-form-urlencoded'
                  },
                  success:()=>{
                    wx.showToast({
                      title: '反馈成功',
                    })
                  }
                })
              } else if (res1.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }else if(res.tapIndex==1){
          wx.navigateTo({
            url: '/pages/gradeFeedback/gradeFeedback?grade='+id,
          })
        }
      },
      fail (res) {
        console.log(res.errMsg)
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      admin:wx.getStorageSync('admin')
    },()=>{
      this.init()
    })
  },

  /**初始化列表 */
  init(){
    wx.request({
      url: host+'/client/grade/list?page=0&pageSize='+this.data.pageSize+'&user='+this.data.admin.loginName,
      success:res=>{
        this.setData({
          list:res.data.data.list,
          total:res.data.data.total
        })
      }
    })
  },
  
    /**下拉触底 */
    onReachBottom(){
      if(this.data.pageSize<this.data.total){
        this.setData({
          pageSize:this.data.pageSize+10
        },()=>{
          this.init()
        });
      }else{
        wx.showToast({
          title: '没有更多了',
          icon:'error'
        })
      }
    }
})